package com.loongtech.bi.manager.game;

import com.loongtech.bi.entity.game.EntityNewUser1LevelDistribute;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
/**
 * 用户的三日流失
 * @author lihui
 *
 */
@Service
public class NewUser1LevelDistributeManager extends ManagerQueryCacheBase<EntityNewUser1LevelDistribute> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 获取所有平台的人数，按照等级分组
	 * @return
	 */
	public List<Object[]> getAllKindUserNumberGroupByLevel(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select level,sum(user_number) from EntityNewUser1LevelDistribute where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level order by sum(user_number) desc ", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 获取所有平台的人数
	 * @return
	 */
	public List<Object[]> getAllKindUserNumber(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer)  {
		return findByQuery("select sum(user_number),count(user_number) from EntityNewUser1LevelDistribute where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' ", "dayStart", dateStart, "dayEnd", dateEnd);
	}

    /**
     *
     * @param startDate
     * @param endDate
     * @param queryPlatform
     * @param queryChannel
     * @param queryServer
     * @param minLevel
     * @return
     */
    public List<Object[]> getAllKindUserNumberGroupByLevel(Date startDate, Date endDate, String queryPlatform, String queryChannel, String queryServer, int minLevel) {
        return findByQuery("select date_format(day,'%Y-%m-%d'),level,user_number from EntityNewUser1LevelDistribute where day>=:startDate and day<=:endDate and platformid=:queryPlatform and channelid=:queryChannel and serverid=:queryServer and level >= :minLevel ",
                "startDate", startDate,
                "endDate", endDate,
                "queryPlatform", queryPlatform,
                "queryChannel", queryChannel,
                "queryServer", queryServer,
                "minLevel", minLevel);
    }
}
